Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minifying pynars requirements to allow running in constrained environ… #103

Merged
merged 1 commit into from
May 2, 2024

Conversation

maxeeem
Copy link
Collaborator

@maxeeem maxeeem commented Apr 30, 2024

…ments like python emulators

Please double check my changes to make sure it still does the same calculations as numpy code. With these modifications I am able to run pynars on iOS using iSH :)

@maxeeem maxeeem requested review from ccrock4t and bowen-xu April 30, 2024 19:33
Copy link

dev.txt - DEV BRANCH: FAILED (failures=54, errors=13)
pr.txt - PR BRANCH: FAILED (failures=54, errors=12)

--- dev.txt	2024-04-30 19:36:23.399818523 +0000
+++ pr.txt	2024-04-30 19:36:23.403818564 +0000
@@ -3,7 +3,7 @@
 test_abduction (test_NAL1.TEST_NAL1)
 'Abduction ... ok
 test_backward_inference (test_NAL1.TEST_NAL1)
-' Backward inference ... FAIL
+' Backward inference ... ok
 test_conversion (test_NAL1.TEST_NAL1)
 'Conversion ... ok
 test_deduction (test_NAL1.TEST_NAL1)
@@ -93,7 +93,7 @@
 test_uni_decomposition_3 (test_NAL3.TEST_NAL3)
 'What differs boys from gials are being strong. ... FAIL
 test_structural_transformation_0 (test_NAL4.TEST_NAL4)
-'Structural transformation ... ok
+'Structural transformation ... FAIL
 test_structural_transformation_1 (test_NAL4.TEST_NAL4)
 'Structural transformation ... ok
 test_structural_transformation_10 (test_NAL4.TEST_NAL4)
@@ -260,7 +260,7 @@
 test_unification_4 (test_NAL6.TEST_NAL6)
 'Variable unification ... ok
 test_unification_5 (test_NAL6.TEST_NAL6)
-'Variable unification ... ERROR
+'Variable unification ... ok
 test_unification_5_1 (test_NAL6.TEST_NAL6)
 'Variable unification ... ok
 test_unification_6 (test_NAL6.TEST_NAL6)
@@ -315,7 +315,7 @@
 test_inference_on_tense_1 (test_NAL7.TEST_NAL7)
 ' inference on tense ... FAIL
 test_inference_on_tense_2 (test_NAL7.TEST_NAL7)
-' inference on tense ... FAIL
+' inference on tense ... ok
 test_analogy_0_0__0 (test_NAL7.TEST_NAL7_ANALOGY) ... ok
 test_analogy_0_0__1 (test_NAL7.TEST_NAL7_ANALOGY) ... ok
 test_analogy_0_0__2 (test_NAL7.TEST_NAL7_ANALOGY) ... ok
@@ -381,7 +381,7 @@
 test_sequence_1 (test_NAL8.TEST_NAL8)
 C! ... ok
 test_sequence_2 (test_NAL8.TEST_NAL8)
-(&/, A, B, C)! ... ok
+(&/, A, B, C)! ... FAIL
 test_anticipate_0 (test_NAL9.TEST_NAL9)
 <<(&/,<a --> A>,+10) =/> <b --> B>>. ... ok
 test_believe_0 (test_NAL9.TEST_NAL9)

Copy link
Collaborator

@bowen-xu bowen-xu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty complicated. Is it not enough to check equality of 1.) term connector and 2.) constituent terms?

@@ -358,9 +357,13 @@ def equal(self, o: Type['Compound']) -> bool:
set2: Iterable[Term] = o.terms - self.terms
if len(set1) == len(set2) == 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to put the comment on the equality function. Couldnt we end on this line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that’s a question for @bowen-xu
I’m not sure what the original rationale for this code was.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for handling variable things.
(&&, <#x-->bird>, <#x-->animal>) and (&&, <robin-->bird>, <robin-->animal>) are "equal". There is a similar function identical() that compars the hash values of two terms.
The two compounds above has different hash values, and the difference is not empty, though they are "equal".

# is greater than zero. The zip(*eq_array) unpacks each row of eq_array into columns.
eq_array = [[term1.equal(term2)
for term2 in set2] for term1 in set1]
if all(sum(col) > 0 for col in zip(*eq_array)) and all(sum(row) > 0 for row in eq_array):
Copy link
Collaborator

@ccrock4t ccrock4t May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of numpy equivalence, I think in this case they are equivalent, but not in all cases. I can see a difference in the behaviors of the previous code vs this code if the "sum()" values could possibly result in negative integers/floats.

I think that will not be an issue here, since it seems like we are summing Boolean values here, which are interpreted as 1 and 0. Though summing Booleans in the first place seems iffy.

Copy link
Collaborator

@ccrock4t ccrock4t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, as they are functionally equivalent.

@bowen-xu bowen-xu self-requested a review May 2, 2024 00:22
@bowen-xu bowen-xu merged commit f866c4e into dev May 2, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants